-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix (jkube-kit/enricher) : YAML multiline annotations incorrectly serialized on windows #3014
fix (jkube-kit/enricher) : YAML multiline annotations incorrectly serialized on windows #3014
Conversation
Eclipse JKube CI ReportStarted new GH workflow run for #3014 (2024-05-06T10:20:52Z) ⚙️ JKube E2E Tests (8967299429)
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3014 +/- ##
=============================================
+ Coverage 59.36% 70.87% +11.51%
- Complexity 4586 5087 +501
=============================================
Files 500 490 -10
Lines 21211 19595 -1616
Branches 2830 2528 -302
=============================================
+ Hits 12591 13888 +1297
+ Misses 7370 4479 -2891
+ Partials 1250 1228 -22 ☔ View full report in Codecov by Sentry. |
if (value.contains(System.lineSeparator()) && !value.endsWith(System.lineSeparator())) { | ||
return value + System.lineSeparator(); | ||
if (containsAny(value, "\r?\n") && !value.endsWith("\n")) { | ||
return value.replaceAll("\r?\n", "\n") + "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get about the replaceAll
call.
I think that it'd be easier if you got a matcher and then appended whatever matched (either \n
or \r\n
)
@DisplayName("Yaml scalar with multi line values") | ||
class YamlScalarWithMultilineString { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if scalar is the relevant part or neither what we want to test.
If it is, I guess a suitable description is Multi-line strings are serialized to YAML using scalar blocks
8fdf3cb
to
c399390
Compare
Matcher m = CONTAINS_LINE_BREAK.matcher(value); | ||
String matchedLineBreak = null; | ||
while (m.find()) { | ||
matchedLineBreak = m.group(); | ||
} | ||
if (matchedLineBreak != null && !value.endsWith("\n")) { | ||
return value.replaceAll(matchedLineBreak, "\n") + "\n"; | ||
} | ||
return value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to discuss this again, since in our last sync this is not what we discussed.
The idea was to match a line break, and then append the match:
if (m.find()) {
String eol = m.group();
if (!value.endsWith(eol) {
return value + eol;
}
}
return value;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I tested this and it seems to make test pass. I've updated it as per your suggestion.
…ialized on windows Related to eclipse-jkube#2841 Currently for enforcing trailing newline in case of multi line strings in resource annotations, we were relying on presence of `System.lineSeparator()`. This was causing problems as YAML multiline scalar values are converted into strings with Line Feed (`\n`) endings when they're deserialized into objects. Modify logic in MetadataVisitor with respect to this behavior. Signed-off-by: Rohan Kumar <[email protected]>
c399390
to
2c0ca60
Compare
Quality Gate passedIssues Measures |
Description
Related to #2841
Currently for enforcing trailing newline in case of multi line strings in resource annotations, we were relying on presence of
System.lineSeparator()
.This was causing problems as YAML multiline scalar values are converted into strings with Line Feed (
\n
) endings when they're deserialized into objects. I checked in YAML spec and found this:https://yaml.org/spec/1.2.2/#line-break-characters
Modify logic in MetadataVisitor with respect to this behavior.
With this change, kubernetes-maven-plugin/it/metadata-labels-annotations integration test is passing on Windows
Type of change
test, version modification, documentation, etc.)
Checklist